package com.ibm.ems.servlets;


import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ibm.ems.dao.FeedbackDAO;
import com.ibm.ems.dao.SpeakerDAO;
import com.ibm.ems.dto.Feedback;
import com.ibm.ems.dto.Speaker;
import com.ibm.ems.util.ConnectionUtil;


/**
 * Servlet implementation class GetSpeakerEventData
 */
public class GetSpeakerEventData extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		
		Connection conn = ConnectionUtil.getConnection();
		SpeakerDAO spDAO = new SpeakerDAO(conn);
		FeedbackDAO fpDAO= new FeedbackDAO(conn);
		
		String user=request.getRemoteUser();
		System.out.println(user);
		
		String idString =  request.getParameter("EventId");
		String commentId= request.getParameter("EventId");
		
		if (idString != null || commentId!=null) {
			
			Speaker e = new Speaker();
			Feedback f= new Feedback();
			
			e.setEventId(Integer.parseInt(idString));
			f.setEventId(Integer.parseInt(commentId));
			
			try {
				spDAO.getSpeakerDetails(e);
				fpDAO.getFeedbackDetails(f);
				
				ConnectionUtil.closeConnection(conn);
				System.out.println(e.getEventId());
				PrintWriter out = response.getWriter();
				out.println("<h1>Welcome ! <font color='blue'>"+ idString+"</font></h1>");
				  
				  
				System.out.println(f.getEventId());
				
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		} else {
			System.out.println("No Events are Available");
			if(commentId==null){
				System.out.println("No comments");
			}
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
